package com.wang;

import lombok.Data;
import lombok.Value;

import java.security.Key;
import java.util.HashMap;
import java.util.Map;
@Data
/**
 * @ProjectName: untitled
 * @Titile: MapPractice
 * @Author: 王亦凡1
 * @Description: TODO
 */
public class MapPractice {
    public static void main(String[] args) {
        Map<String,String>data=new HashMap<>();
        data.put("小王","A");
        data.put("小张","B");
        data.put("小杨","C");
        data.put("小甘","D");
        data.put("小刘","E");
        data.put("小赵","F");
        data.put("小马","G");
        data.put("小何","H");
        data.put("小雷","H");
          count(data);
    }
      public static void count(Map<String,String>data){
          /**1.创建一个新Map集合，用来存储投票结果
           * 2.遍历DATA集合（key--value)
           * 3.将value拿出来，将value当作类存到新的集合中
           *4.如果A已经存在，那么将A对应的值+1
           * 5.如果A不存在，那么直接将A---1，存储到新Map中
           *6.遍历map集合，打印出来
           * */
              Map<String,String>resultMap=new HashMap<>();
             data.forEach((k,v)->{
                 boolean containsKey=resultMap.containsKey(v);
                 if(containsKey){
                     Integer oldCOUNT= Integer.valueOf(resultMap.get(v));
                     resultMap.put(v, String.valueOf(oldCOUNT+1));

                 }
                 else {
                     resultMap.put(v, String.valueOf(1));
                 }
             });

resultMap.forEach((k,v)->{
    System.out.println(k+"-->"+v);
});


      }

}
